package com.pcbly.web.components.utils.security;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.security.MessageDigest;

public class SHA {
	public static String getSHA(byte[] password) {
		MessageDigest md = null;

        try {
            // first create an instance, given the provider
            md = MessageDigest.getInstance("SHA");
        } catch (Exception e) {
//            log.error("Exception: " + e);

            return password.toString();
        }

        md.reset();

        // call the update method one or more times
        // (useful when you don't know the size of your data, eg. stream)
        md.update(password);

        
        // now calculate the hash
        byte[] encodedPassword = md.digest();

//        StringBuffer buf = new StringBuffer();
//
//        for (int i = 0; i < encodedPassword.length; i++) {
//            if ((encodedPassword[i] & 0xff) < 0x10) {
//                buf.append("0");
//            }
//
//            buf.append(Long.toString(encodedPassword[i] & 0xff, 16));
//        }

        return encodedPassword.toString();
	}
	public static void main(String[] args){
		try
		{
			StringBuffer sbuffer=new StringBuffer();
			File file=new File("D:/pcbenv/skill/place/sym_align.il");
			if(file.canRead()){
				BufferedReader  isreader = new BufferedReader(new FileReader(file));
				String tempString=null;
				int line = 1;
				while((tempString = isreader.readLine()) != null){
//					System.out.println("line " + line + ": " + tempString);
					sbuffer.append(tempString);
					line++;
				}
				isreader.close();
			}
			System.out.println(SHA.getSHA(sbuffer.toString().getBytes()));
		}catch(Exception e){
			
		}
//		String t=getMD5("admin".getBytes());
//		System.out.println(t);
//		t=getMD5("11111111".getBytes());
//		System.out.println(t);
	}
}
